package com.itheima.tanhua.service;


import cn.hutool.core.convert.Convert;
import com.itheima.tanhua.api.db.UserInfoServiceApi;
import com.itheima.tanhua.api.db.UserServiceApi;
import com.itheima.tanhuan.pojo.db.User;
import com.itheima.tanhuan.pojo.db.UserInfo;
import com.itheima.tanhuan.vo.db.HuanXinUserVo;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

@Service
public class HuanXinService {
    @DubboReference
    private UserServiceApi userServiceApi;
    @Autowired
    StringRedisTemplate stringRedisTemplate;
    @DubboReference
    private UserInfoServiceApi userInfoServiceApi;

    public HuanXinUserVo huanxinUser() {
        String uid = stringRedisTemplate.opsForValue().get("UID");
        User user=userServiceApi.findById(Convert.toLong(uid));
        HuanXinUserVo huanXinUserVo=new HuanXinUserVo();
        huanXinUserVo.setUsername(user.getHxUser());
        huanXinUserVo.setPassword(user.getHxPassword());
        return huanXinUserVo;
    }

    public UserInfo userInfo(String huanxinId) {
        //根据环信返回用户id
        User user=userServiceApi.findByHuanxiId(huanxinId);
        return userInfoServiceApi.findById(user.getId());

    }
}
